package 剑指offer;

public class p101对称二叉树 {

    public boolean isSymmetricChild(TreeNode leftTree,TreeNode rightTree) {
        //判断左右子树根是否相同
        if (leftTree==null && rightTree==null) {
            return true;
        }
        if (leftTree==null || rightTree!=null) {
            return false;
        }
        if (leftTree.val!=rightTree.val) {
            return false;
        }

        return isSymmetricChild(leftTree.left,rightTree.right) && isSymmetricChild(leftTree.right,rightTree.left);

    }

    public boolean isSymmetric(TreeNode root) {
        if (root==null) {
            return true;
        }

        return isSymmetricChild(root.left,root.right);
    }
}
